<?php
	require("include/includes.php");
	//require("include/getIP.php");
	
	//
	// --------------------------------- JSON NEWSFEED -----------------------------------
	//
	
	// Valeurs initiales
	$begin = 0;
	if(isset($_GET['begin']) && is_numeric($_GET['begin']))
	{
		$begin=(int)$_GET['begin'];
	}
	$number = 20;
	if(isset($_GET['number']) && is_numeric($_GET['number']))
	{
		$number=(int)$_GET['number'];
	}
	
	// Récupération dans la bdd
	
	// RecordsHistory
	$news = RecordsHistory::getAll($begin, $number);
	$newsArray = Array();
	foreach($news as $element)
	{
		if($element->getAction() == 1)
		{
			$date = new DateTime ($element->getDate());
			$formattedDate = $date->format ('m/d/Y H:i');
			$newsArray[] = Array(
					'playerId' => (int)$element->getId(),
					'playerName' => $element->getPlayer()->getNickName(),
					'trackType' => (string)$element->getTrackType(),
					'trackName' => (string)$element->getTrackName(),
					'time' => Record::timeToString($element->getTime()),
					'rank' => (int)$element->getRank(),
					'mode' => (string)$element->getTrackMode(),
					'version' => (string)$element->getVersion(),
					//'character' => $element->,
					'date' => $formattedDate
				);
		}
	}
	echo json_encode($newsArray);
?>